<template>
  <ElCard>
    <el-form :model="formModel" ref="formRef" :show-message="false"  size="small">
      <CardBox header="眼底">
        <ElFormItem>
          <ElRadioGroup
            v-model="formModel.a00_04_135"
            @change="handleStringIncludeClear($event, '1', ['a00_04_136'])"
          >
            <ElRadio label="1">正常</ElRadio>
            <ElRadio label="2">异常</ElRadio>
          </ElRadioGroup>
        </ElFormItem>
        <ElFormItem
          prop="a00_04_136"
          label=" "
          :required="formModel.a00_04_135 === '2'"
        >
          <ElInput
            v-model="formModel.a00_04_136"
            :disabled="formModel.a00_04_135 !== '2'"
          />
        </ElFormItem>
      </CardBox>
      <br />
      <CardBox header="皮肤">
        <ElFormItem>
          <ElRadioGroup
            v-model="formModel.a00_04_65"
            @change="handleStringExcludeClear($event, '7', ['a00_04_66'])"
          >
            <ElRadio
              v-for="(value, key) in formSource.a00_04_65"
              :label="key"
              :key="key"
              >{{ value }}</ElRadio
            >
          </ElRadioGroup>
        </ElFormItem>
        <ElFormItem
          prop="a00_04_66"
          label=" "
          :required="formModel.a00_04_65 === '7'"
        >
          <ElInput
            v-model="formModel.a00_04_66"
            :disabled="formModel.a00_04_65 !== '7'"
            maxlength="25"
            show-word-limit
          />
        </ElFormItem>
      </CardBox>
      <br />

      <CardBox header="巩膜">
        <ElFormItem prop="a00_04_67">
          <ElRadioGroup
            v-model="formModel.a00_04_67"
            @change="handleStringExcludeClear($event, '4', ['a00_04_68'])"
          >
            <ElRadio
              v-for="(value, key) in formSource.a00_04_67"
              :label="key"
              :key="key"
              >{{ value }}</ElRadio
            >
          </ElRadioGroup>
        </ElFormItem>
        <ElFormItem
          prop="a00_04_68"
          label=" "
          :required="formModel.a00_04_67 === '4'"
        >
          <ElInput
            v-model="formModel.a00_04_68"
            :disabled="formModel.a00_04_67 !== '4'"
            maxlength="15"
            show-word-limit
          />
        </ElFormItem>
      </CardBox>
      <br />

      <CardBox header="淋巴结">
        <ElFormItem prop="a00_04_69">
          <ElRadioGroup
            v-model="formModel.a00_04_69"
            @change="handleStringExcludeClear($event, '4', ['a00_04_70'])"
          >
            <ElRadio
              v-for="(value, key) in formSource.a00_04_69"
              :label="key"
              :key="key"
              >{{ value }}</ElRadio
            >
          </ElRadioGroup>
        </ElFormItem>
        <ElFormItem
          prop="a00_04_70"
          label=" "
          :required="formModel.a00_04_69 === '4'"
        >
          <ElInput
            v-model="formModel.a00_04_70"
            :disabled="formModel.a00_04_69 !== '4'"
            maxlength="25"
            show-word-limit
          />
        </ElFormItem>
      </CardBox>
      <br />
      <CardBox header="肺">
        <ElFormItem prop="a00_04_71" label="桶状胸">
          <ElRadioGroup
            v-model="formModel.a00_04_71"
            @change="handleStringExcludeClear($event, '2', ['a00_04_72'])"
          >
            <ElRadio
              v-for="(value, key) in formSource.no_or_yes"
              :label="key"
              :key="key"
              >{{ value }}</ElRadio
            >
          </ElRadioGroup>
        </ElFormItem>
        <ElFormItem
          prop="a00_04_72"
          label=" "
          :required="formModel.a00_04_71 === '2'"
        >
          <ElInput
            v-model="formModel.a00_04_72"
            :disabled="formModel.a00_04_71 !== '2'"
            maxlength="25"
            show-word-limit
          />
        </ElFormItem>
        <br />
        <ElFormItem prop="a00_04_73" label="呼吸音">
          <ElRadioGroup
            v-model="formModel.a00_04_73"
            @change="handleStringExcludeClear($event, '2', ['a00_04_74'])"
          >
            <ElRadio
              v-for="(value, key) in formSource.normal_abnormal"
              :label="key"
              :key="key"
              >{{ value }}
            </ElRadio>
          </ElRadioGroup>
        </ElFormItem>
        <ElFormItem
          prop="a00_04_74"
          label=" "
          :required="formModel.a00_04_73 === '2'"
        >
          <ElInput
            v-model="formModel.a00_04_74"
            :disabled="formModel.a00_04_73 !== '2'"
            maxlength="25"
            show-word-limit
          />
        </ElFormItem>
        <br />
        <ElFormItem prop="a00_04_75" label="罗音">
          <ElRadioGroup
            v-model="formModel.a00_04_75"
            @change="handleStringExcludeClear($event, '4', ['a00_04_76'])"
          >
            <ElRadio
              v-for="(value, key) in formSource.a00_04_75"
              :label="key"
              :key="key"
              >{{ value }}</ElRadio
            >
          </ElRadioGroup>
        </ElFormItem>
        <ElFormItem
          prop="a00_04_76"
          label=" "
          :required="formModel.a00_04_75 === '4'"
        >
          <ElInput
            v-model="formModel.a00_04_76"
            :disabled="formModel.a00_04_75 !== '4'"
            maxlength="25"
            show-word-limit
          />
        </ElFormItem>
      </CardBox>
      <br />
      <CardBox header="心脏">
        <ElFormItem prop="a00_04_78" label="心律">
          <ElRadioGroup v-model="formModel.a00_04_78">
            <ElRadio
              v-for="(value, key) in formSource.a00_04_78"
              :label="key"
              :key="key"
              >{{ value }}</ElRadio
            >
          </ElRadioGroup>
        </ElFormItem>
        <ElFormItem prop="a00_04_77" label="心率" v-if="!isHealthCheck">
          <ElInput v-model="formModel.a00_04_77" type="number">
            <template #append> 次/分钟</template>
          </ElInput>
        </ElFormItem>
        <br />
        <ElFormItem prop="a00_04_79" label="杂音">
          <ElRadioGroup
            v-model="formModel.a00_04_79"
            @change="handleStringExcludeClear($event, '2', ['a00_04_80'])"
          >
            <ElRadio
              v-for="(value, key) in formSource.no_or_has"
              :label="key"
              :key="key"
              >{{ value }}</ElRadio
            >
          </ElRadioGroup>
        </ElFormItem>
        <ElFormItem
          prop="a00_04_80"
          label=" "
          :required="formModel.a00_04_79 === '2'"
        >
          <ElInput
            v-model="formModel.a00_04_80"
            :disabled="formModel.a00_04_79 !== '2'"
            maxlength="25"
            show-word-limit
          />
        </ElFormItem>
      </CardBox>
      <br />
      <CardBox header="腹部">
        <ElFormItem prop="a00_04_81" label="压痛">
          <ElRadioGroup
            v-model="formModel.a00_04_81"
            @change="handleStringExcludeClear($event, '2', ['a00_04_82'])"
          >
            <ElRadio
              v-for="(value, key) in formSource.no_or_has"
              :label="key"
              :key="key"
              >{{ value }}</ElRadio
            >
          </ElRadioGroup>
        </ElFormItem>
        <ElFormItem
          prop="a00_04_82"
          label=" "
          :required="formModel.a00_04_81 === '2'"
        >
          <ElInput
            v-model="formModel.a00_04_82"
            :disabled="formModel.a00_04_81 !== '2'"
            maxlength="25"
            show-word-limit
          />
        </ElFormItem>
        <br />
        <ElFormItem prop="a00_04_83" label="包块">
          <ElRadioGroup
            v-model="formModel.a00_04_83"
            @change="handleStringExcludeClear($event, '2', ['a00_04_84'])"
          >
            <ElRadio
              v-for="(value, key) in formSource.no_or_has"
              :label="key"
              :key="key"
              >{{ value }}</ElRadio
            >
          </ElRadioGroup>
        </ElFormItem>
        <ElFormItem
          prop="a00_04_84"
          label=" "
          :required="formModel.a00_04_83 === '2'"
        >
          <ElInput
            v-model="formModel.a00_04_84"
            :disabled="formModel.a00_04_83 !== '2'"
            maxlength="25"
            show-word-limit
          />
        </ElFormItem>
        <br />
        <ElFormItem prop="a00_04_85" label="肝大">
          <ElRadioGroup
            v-model="formModel.a00_04_85"
            @change="handleStringExcludeClear($event, '2', ['a00_04_86'])"
          >
            <ElRadio
              v-for="(value, key) in formSource.no_or_has"
              :label="key"
              :key="key"
              >{{ value }}</ElRadio
            >
          </ElRadioGroup>
        </ElFormItem>
        <ElFormItem
          prop="a00_04_86"
          label=" "
          :required="formModel.a00_04_85 === '2'"
        >
          <ElInput
            v-model="formModel.a00_04_86"
            :disabled="formModel.a00_04_85 !== '2'"
            maxlength="25"
            show-word-limit
          />
        </ElFormItem>
        <br />
        <ElFormItem prop="a00_04_87" label="脾大">
          <ElRadioGroup
            v-model="formModel.a00_04_87"
            @change="handleStringExcludeClear($event, '2', ['a00_04_88'])"
          >
            <ElRadio
              v-for="(value, key) in formSource.no_or_has"
              :label="key"
              :key="key"
              >{{ value }}</ElRadio
            >
          </ElRadioGroup>
        </ElFormItem>
        <ElFormItem
          prop="a00_04_88"
          label=" "
          :required="formModel.a00_04_87 === '2'"
        >
          <ElInput
            v-model="formModel.a00_04_88"
            :disabled="formModel.a00_04_87 !== '2'"
            maxlength="25"
            show-word-limit
          />
        </ElFormItem>
        <br />
        <ElFormItem prop="a00_04_89" label="移动性浊音">
          <ElRadioGroup
            v-model="formModel.a00_04_89"
            @change="handleStringExcludeClear($event, '2', ['a00_04_90'])"
          >
            <ElRadio
              v-for="(value, key) in formSource.no_or_has"
              :label="key"
              :key="key"
              >{{ value }}</ElRadio
            >
          </ElRadioGroup>
        </ElFormItem>
        <ElFormItem
          prop="a00_04_90"
          label=" "
          :required="formModel.a00_04_89 === '2'"
        >
          <ElInput
            v-model="formModel.a00_04_90"
            :disabled="formModel.a00_04_89 !== '2'"
            maxlength="25"
            show-word-limit
          />
        </ElFormItem>
      </CardBox>
      <br />
      <CardBox header="下肢水肿">
        <ElFormItem prop="a00_04_91">
          <ElRadioGroup v-model="formModel.a00_04_91">
            <ElRadio
              v-for="(value, key) in formSource.a00_04_91"
              :label="key"
              :key="key"
              >{{ value }}</ElRadio
            >
          </ElRadioGroup>
        </ElFormItem>
      </CardBox>
      <br />
      <CardBox header="足背动脉搏动">
        <ElFormItem prop="a00_04_92">
          <ElRadioGroup v-model="formModel.a00_04_92">
            <ElRadio
              v-for="(value, key) in formSource.a00_04_92"
              :label="key"
              :key="key"
              >{{ value }}</ElRadio
            >
          </ElRadioGroup>
        </ElFormItem>
      </CardBox>
      <br />
      <CardBox header="肛门指诊">
        <ElFormItem prop="a00_04_93">
          <ElRadioGroup
            v-model="formModel.a00_04_93"
            @change="handleStringExcludeClear($event, '5', ['a00_04_94'])"
          >
            <ElRadio
              v-for="(value, key) in formSource.a00_04_93"
              :label="key"
              :key="key"
              >{{ value }}</ElRadio
            >
          </ElRadioGroup>
        </ElFormItem>
        <ElFormItem
          prop="a00_04_94"
          label=" "
          :required="formModel.a00_04_93 === '5'"
        >
          <ElInput
            v-model="formModel.a00_04_94"
            :disabled="formModel.a00_04_93 !== '5'"
            maxlength="25"
            show-word-limit
          />
        </ElFormItem>
      </CardBox>
      <br />
      <CardBox header="乳腺">
        <ElFormItem prop="a00_04_95">
          <ElCheckboxGroup
            v-model="formModel.a00_04_95"
            @change="handleArrayExcludeClear($event, '5', ['a00_04_94'])"
          >
            <ElCheckbox
              @change="handle95Change($event, key)"
              v-for="(value, key) in formSource.a00_04_95"
              :label="key"
              :key="key"
              >{{ value }}
            </ElCheckbox>
          </ElCheckboxGroup>
        </ElFormItem>
        <ElFormItem
          prop="a00_04_96"
          label=" "
          :required="formModel.a00_04_95?.includes('5')"
        >
          <ElInput
            v-model="formModel.a00_04_96"
            :disabled="!formModel.a00_04_95?.includes('5')"
            maxlength="25"
            show-word-limit
          />
        </ElFormItem>
      </CardBox>
      <br />
      <CardBox header="妇科">
        <ElFormItem prop="a00_04_97" label="外阴">
          <ElRadioGroup
            v-model="formModel.a00_04_97"
            @change="handleStringExcludeClear($event, '2', ['a00_04_98'])"
          >
            <ElRadio
              v-for="(value, key) in formSource.no_abnormal"
              :label="key"
              :key="key"
              >{{ value }}</ElRadio
            >
          </ElRadioGroup>
        </ElFormItem>
        <ElFormItem
          prop="a00_04_98"
          label=" "
          :required="formModel.a00_04_97 === '2'"
        >
          <ElInput
            v-model="formModel.a00_04_98"
            :disabled="formModel.a00_04_97 !== '2'"
            maxlength="25"
            show-word-limit
          />
        </ElFormItem>
        <br />
        <ElFormItem prop="a00_04_99" label="阴道">
          <ElRadioGroup
            v-model="formModel.a00_04_99"
            @change="handleStringExcludeClear($event, '2', ['a00_04_100'])"
          >
            <ElRadio
              v-for="(value, key) in formSource.no_abnormal"
              :label="key"
              :key="key"
              >{{ value }}</ElRadio
            >
          </ElRadioGroup>
        </ElFormItem>
        <ElFormItem
          prop="a00_04_100"
          label=" "
          :required="formModel.a00_04_99 === '2'"
        >
          <ElInput
            v-model="formModel.a00_04_100"
            :disabled="formModel.a00_04_99 !== '2'"
            maxlength="25"
            show-word-limit
          />
        </ElFormItem>
        <br />
        <ElFormItem prop="a00_04_101" label="宫颈">
          <ElRadioGroup
            v-model="formModel.a00_04_101"
            @change="handleStringExcludeClear($event, '2', ['a00_04_102'])"
          >
            <ElRadio
              v-for="(value, key) in formSource.no_abnormal"
              :label="key"
              :key="key"
              >{{ value }}</ElRadio
            >
          </ElRadioGroup>
        </ElFormItem>
        <ElFormItem
          prop="a00_04_102"
          label=" "
          :required="formModel.a00_04_101 === '2'"
        >
          <ElInput
            v-model="formModel.a00_04_102"
            :disabled="formModel.a00_04_101 !== '2'"
            maxlength="25"
            show-word-limit
          />
        </ElFormItem>
        <br />
        <ElFormItem prop="a00_04_103" label="宫体">
          <ElRadioGroup
            v-model="formModel.a00_04_103"
            @change="handleStringExcludeClear($event, '2', ['a00_04_104'])"
          >
            <ElRadio
              v-for="(value, key) in formSource.no_abnormal"
              :label="key"
              :key="key"
              >{{ value }}</ElRadio
            >
          </ElRadioGroup>
        </ElFormItem>
        <ElFormItem
          prop="a00_04_104"
          label=" "
          :required="formModel.a00_04_103 === '2'"
        >
          <ElInput
            v-model="formModel.a00_04_104"
            :disabled="formModel.a00_04_103 !== '2'"
            maxlength="25"
            show-word-limit
          />
        </ElFormItem>
        <br />
        <ElFormItem prop="a00_04_105" label="附件">
          <ElRadioGroup
            v-model="formModel.a00_04_105"
            @change="handleStringExcludeClear($event, '2', ['a00_04_106'])"
          >
            <ElRadio
              v-for="(value, key) in formSource.no_abnormal"
              :label="key"
              :key="key"
              >{{ value }}</ElRadio
            >
          </ElRadioGroup>
        </ElFormItem>
        <ElFormItem
          prop="a00_04_106"
          label=" "
          :required="formModel.a00_04_105 === '2'"
        >
          <ElInput
            v-model="formModel.a00_04_106"
            :disabled="formModel.a00_04_105 !== '2'"
            maxlength="25"
            show-word-limit
          />
        </ElFormItem>
      </CardBox>
      <br />
      <CardBox header="其他">
        <ElFormItem prop="a00_04_107" style="width: 100%">
          <ElInput
            v-model="formModel.a00_04_107"
            type="textarea"
            maxlength="25"
            show-word-limit
          />
        </ElFormItem>
      </CardBox>
    </el-form>
  </ElCard>
</template>

<script lang="ts" setup>
import { ICheckBody } from "@/model";
import { reactive, ref, toRaw, watch } from "vue";
import { tjwx } from "@/dict";
import formUtils from "./formUtils";
import { ElForm } from "element-plus";
import { cloneDeep } from "lodash-es";

const props = defineProps<{
  checkBody: ICheckBody;
}>();
const isHealthCheck = ref<boolean>(import.meta.env.MODE === "health_check");
console.log(props.checkBody);
const formSource = reactive(tjwx);
const formModel = ref(cloneDeep(props.checkBody));
// watch(
//   () => {
//     return props.checkBody;
//   },
//   (val) => {
//     formModel.value = val;
//   }
// );
const {
  handleStringExcludeClear,
  handleArrayExcludeClear,
  handleStringIncludeClear,
} = formUtils(formModel);
const formRef = ref<InstanceType<typeof ElForm>>();
const validateForm = () => {
  return formRef.value?.validate();
};

const handle95Change = (value: boolean | string | number, key: string) => {
  if (key === "1" && value === true) {
    formModel.value.a00_04_95 = ["1"];
  } else {
    formModel.value.a00_04_95 =
      formModel.value.a00_04_95?.filter((item) => item !== "1") || [];
  }
};
const getData = () => {
  return toRaw(formModel.value);
};

defineExpose({ validateForm, getData });
</script>

<style scoped></style>
